<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>prototype</title>
</head>
<body>
<script type="text/javascript">
var p1 = new Promise(function(resolve,reject) {
	setTimeout(()=> {
		console.log(1)
		resolve(1)
	},300)   
})

p1.then(val => {
	return new Promise(function(resolve,reject) {
		setTimeout(()=> {
			++ val
			console.log(val)
			resolve(val)
		},300)   
	})
})
.then(val => {
	return new Promise(function(resolve,reject) {
		setTimeout(()=> {
			++ val
			console.log(val)
			++ a
			//reject('妈蛋')
			resolve(val)
		},300)   
	})
})
.then(val => {
	return new Promise(function(resolve,reject) {
		setTimeout(()=> {
			++ val
			console.log(val)
			resolve(val)
		},300)   
	})
},err => {
	console.log('执行了reject: ' + err)
})
.then(val => {
	console.log('结尾：' + val)
},err => {
	console.log('结尾捕获异常：' + err)
})
.catch(err => {
	console.log('打印错误:' + err)
})

</script>
</body>
</html>




